package com.webtest.jsptest;

import javax.servlet.*;
import java.io.IOException;
import java.util.Enumeration;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2018/7/24 8:31
 *
 * 自顶一个的一个servlet接口的实现类，目标是让开发的任何servlet都继承该类，以简化开发
 */
public abstract class AbstractMyGenericServlet implements Servlet, ServletConfig {

    private ServletContext context;
    private ServletConfig config;

    public ServletContext getContext() {
        return context;
    }

    public ServletConfig getConfig() {
        return config;
    }

    @Override
    public void init(ServletConfig servletConfig) throws ServletException {
        this.context = servletConfig.getServletContext();
        this.config = servletConfig;
    }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

    @Override
    public abstract void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException;

    @Override
    public String getServletInfo() {
        return null;
    }

    @Override
    public void destroy() {

    }

    // 以下为servletConfing接口函数

    @Override
    public String getServletName() {
        return config.getServletName();
    }

    @Override
    public ServletContext getServletContext() {
        return config.getServletContext();
    }

    @Override
    public String getInitParameter(String s) {
        return config.getInitParameter(s);
    }

    @Override
    public Enumeration<String> getInitParameterNames() {
        return config.getInitParameterNames();
    }
}
